package com.huawei.cyc;

import java.util.Scanner;

public class Game {
    static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args){
        scanner = new Scanner(System.in);

        String string = "";
        int perNum = 0;
        int comNum = 0;
        do {
            int num1 = personTOFist();
            System.out.println("人出：" + toFist(num1));
            int num2 = computerToFist();
            System.out.println("电脑出：" + toFist(num2));

            String rel = isWin(num1, num2);
            System.out.println(rel);
            if (rel.equals("人赢")) {
                perNum++;
                comNum--;
            } else if (rel.equals("你输了，电脑赢了！")) {
                perNum--;
                comNum++;
            }
            System.out.println("人得分：" + perNum);
            System.out.println("电脑得分：" + comNum);
            System.out.println("请输入是否继续 y/n");
            string = scanner.nextLine();
            if (string.equals("n")) {
                break;
            }
        }while (string.equals("y"));
        System.out.println("人得分："+perNum);
        System.out.println("电脑得分："+comNum);
        scanner.close();
    }
    public static int personTOFist(){
        System.out.println("人：请出拳 输入1石头 2剪刀 3布");
        String string = scanner.nextLine();
        int num =Integer.parseInt(string);
        return num;
    }
    public static int computerToFist(){
        int num = (int)(Math.random()*(3-1+1)+1);
        return num;
    }
    public static String toFist(int num){
        String string = "";
        switch (num){
            case 1: ;
                string = "石头";
                 break;
            case 2:
                string = "剪刀";
                break;
            case 3:
                string = "布";
                break;
            default:
                string = "放弃";
                break;
        }
        return string;
    }
    public static String isWin(int num1,int num2){
        int rel = num1-num2;
        if (rel== -1 || rel == 2){
            return "你赢了";
        }else if (rel==0){
            return "平手";
        }else {
            return "你输了，电脑赢了";
        }
    }


}
